using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Beta_fundies_controls_comments_EditComment : Controls.DataManagerCommentControl
{
    private DAL.User CurrentUser
    {
        get
        {
            return Managers.UserLoginManager.CurrentUser;
        }
    }

    private string CurrentIP
    {
        get
        {
            return HttpContext.Current.Request.UserHostAddress;
        }
    }

    protected override void ItemChanged()
    {
        if (CurrentComment != null)
        {
            if (IsEditable())
            {
                if (IsAdmin() || CurrentComment.DatePosted >= DateTime.Now.AddHours(-1))
                {
                    mviewComment.SetActiveView(viewComment);
                    EditCommentForm1.CurrentComment = CurrentComment;
                }
                else
                {
                    mviewComment.SetActiveView(viewTooLateAsshole);
                }
            }
            else
            {
                mviewComment.SetActiveView(viewNoEdit);
            }
        }
        else
        {
            mviewComment.SetActiveView(viewError);
        }
    }

    private bool IsAdmin()
    {
        return CurrentUser != null && CurrentUser.HasPermissions(DAL.User.UserStatus.Moderator);
    }

    private bool IsEditable()
    {
        return IsAdmin() || CurrentComment.IPAddress.Equals(CurrentIP);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            CurrentComment = GetItemFromQueryString();
        }
    }
}
